package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-07-07 16:38
 */
public class 题库_0204_计数质数 {

  static
  class Solution {
    public int countPrimes(int n) {
      int answer = 0;
      for (int i = 2; i < n; ++i) {
        if (isPrime(i)) {
          ++answer;
        }
      }
      return answer;
    }

    private boolean isPrime(int num) {
      for (int i = 2; i * i <= num; ++i) {
        if (num % i == 0) {
          return false;
        }
      }
      return true;
    }
  }

}
